package org.tobuy.servlet;

import java.io.IOException;
import java.io.PrintWriter;
import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.tobuy.vo.*;
import org.tobuy.factory.*;

public class ShowAuction extends HttpServlet {

	public void doGet(HttpServletRequest req, HttpServletResponse resp)
			throws ServletException, IOException {
		List<Auction> auctions = new ArrayList<Auction>();
		List<Item> items = new ArrayList<Item>();
		String path = "index.jsp?action=showAuction";
		try {
			auctions = AuctionDAOFactory.getIAuctionDAOInstance().findAuctions();
			Iterator<Auction> auctionIter = auctions.iterator();
			while(auctionIter.hasNext()){
				Auction auction = auctionIter.next();
				Item item = ItemDAOFactory.getIItemDAOInstance().findItem(Integer.toString(auction.getItem_id()));
				items.add(item);
			}
		} catch (Exception e) {
			e.printStackTrace();
		}
		
		req.setAttribute("auctions", auctions);
		req.setAttribute("items", items);
		req.getRequestDispatcher(path).forward(req, resp);
		
	}

	
	public void doPost(HttpServletRequest req, HttpServletResponse resp)
			throws ServletException, IOException {
		this.doGet(req, resp);
	}

}
